package com.dure.commonlib.util;

import org.mozilla.intl.chardet.nsDetector;

import java.io.BufferedInputStream;
import java.io.IOException;

/**
 * Created by Victor on 2016/6/1.
 */
public class CharDetectUtil {

    public static void detectTxtChar( nsDetector det,BufferedInputStream imp){


        byte[] buf = new byte[1024] ;
        int len;
        boolean done = false ;
        boolean isAscii = true ;

        try {
            while( (len=imp.read(buf,0,buf.length)) != -1) {

                // Check if the stream is only ascii.
                if (isAscii)
                    isAscii = det.isAscii(buf,len);

                // DoIt if non-ascii and not done yet.
                if (!isAscii && !done)
                    done = det.DoIt(buf,len, false);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        det.DataEnd();
    }
}
